﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net.Mail;
using System.Web;

namespace Concordia.Utilities
{
    public class Emailer
    {
        private readonly String to;
        private readonly String from;
        
        public Emailer(String _to)
        {
            to = _to;
            from = Properties.Settings.Default.CompanyEmail;
        }

        public void SendWelcome(String firstname, String username)
        {
            var subject = Properties.Settings.Default.WelcomeEmailSubject;
            var body = getBodyTemplate(firstname, username);
            Send(body, subject);
        }

        private void Send(String body, String subject)
        {
            MailMessage mail = new MailMessage(from, to, subject, body);
            String mailHost = Properties.Settings.Default.SmptMailHost;
            SmtpClient client = new SmtpClient(mailHost);

            try
            {
                client.Send(mail);
            }
            catch (Exception ex)
            {
                //todo:  logo error
                String s = ex.ToString();
            }
        }

        private static String getBodyTemplate(String firstname, String username)
        {
            return "Hi " + firstname + "," + Environment.NewLine + Environment.NewLine + "Your username is " + username;
        }
    }
}